package com.zlzxm.shoesmarket.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.ADClubNote;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityClubNote;
import com.zlzxm.shoesmarket.viewmodel.VMClub;

import java.util.List;

/**
 * CREATE BY zlzxm ON 4/7/21
 */
public class FMNavigationClub extends BaseFragment{


    private RecyclerView recyclerView;

    private VMClub vmClub;

    private ADClubNote adClubNote;

    private View foot;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_navigation_club,container,false);
    }

    @Override
    protected void initView(@NonNull View view, @NonNull Bundle savedInstanceState) {
        super.initView(view, savedInstanceState);

        foot = LayoutInflater.from(getContext()).inflate(R.layout.layout_list_foot,null);

        recyclerView = ZViewHelp.findById(view,R.id.recyclerView);

    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        vmClub = new ViewModelProvider(this).get(VMClub.class);

        vmClub.getLiveNote().observe(this, new Observer<List<EntityClubNote>>() {
            @Override
            public void onChanged(List<EntityClubNote> clubNoteEntities) {

                adClubNote.setList(clubNoteEntities);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        adClubNote = new ADClubNote(null);

        adClubNote.setFooterView(foot);

        recyclerView.setAdapter(adClubNote);

        vmClub.requestNote();
    }
}
